﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using CMPPCore.Message;

namespace CMPPMain
{
    public partial class Form1 : Form
    {
        CMPPCore.SMSClient cmppclient;
        public Form1()
        {
            InitializeComponent();
            if (cmppclient == null)
            {
                cmppclient = new CMPPCore.SMSClient(
                   "910000",
                   "111111",
                   "127.0.0.1",
                   7890,
                   new CMPPProtocol.CMPP3Protocol());
                cmppclient.CommandEvent += new EventHandler<CMPPCore.CommandEventArg>(cmppclient_CommandEvent);
            }
        }

        void cmppclient_CommandEvent(object sender, CMPPCore.CommandEventArg e)
        {

            if (e.EventType == CMPPCore.EventType.SubmitSuccess)
            {
                SubmitMessage submit=e.Data as CMPPCore.Message.SubmitMessage;
            
              
            }
           
            if (e.EventType == CMPPCore.EventType.Deliver)
            {
                DeliverMessage deliver = e.Data as CMPPCore.Message.DeliverMessage;
                
                
                this.Invoke(new Action(() =>
                {

                    textBox1.Text += deliver.Deliver.MsgContent;
                }));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool islogin = cmppclient.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            CancelMessage css = cmppclient.CancelSubmitServer(2121);
            //cmppclient.CancelSendSubmit(212121);
            return;

            //DateTime begindt = DateTime.Now;

            for (int i = 0; i < 1; i++)
            {
                cmppclient.Send("098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765438765432109876543210987654321", CMPPProtocol.CMPPEncoding.CODING_ASCII, "09999", new string[] { "111111111" }, "09999", false, CMPPProtocol.CMPPFeeType.Free, CMPPProtocol.CMPPFeeUserType.FeeUser, "", "", "");
            }

            

            //MessageBox.Show((DateTime.Now - begindt).TotalMilliseconds.ToString());
           
        }
    }
}
